from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session, relationship

"""
scoped_session本质上也是一个方法，它首先通过session工厂创建session对象，然后对session对象进行相应的管理。
scoped session采用的是注册模式。
scoped session算是一个全局变量。
"""

from sqlalchemy import Column, Integer, VARCHAR, ForeignKey
from zope.sqlalchemy import register

DBSession = scoped_session(sessionmaker())
register(DBSession)
Base = declarative_base()


class Student(Base):
    __tablename__ = 'student'
    id = Column(Integer, primary_key=True, nullable=False)
    name = Column(VARCHAR(255), unique=True)
    percent = Column(Integer)


class Ftprecode(Base):
    __tablename__ = 'ftprecode'
    id = Column(Integer, primary_key=True, nullable=False, comment="主键")
    department = Column(VARCHAR(255), nullable=False, unique=False, comment="部门")
    employee = Column(VARCHAR(255), nullable=True, unique=False, comment="员工")
    account = Column(VARCHAR(255), nullable=False, unique=True, comment="账号")
    pwd = Column(VARCHAR(255), nullable=False, unique=False, comment="密码")
    groupname = Column(VARCHAR(255), nullable=False, unique=False, comment="组别")


# class User(Base):
#     __tablename__ = 'users'
#     id = Column(Integer, primary_key=True)
#     username = Column(VARCHAR(255))
#     password = Column(VARCHAR(255))
#     groups = relationship('Group', secondary='user_groups')
#
#
# class Group(Base):
#     __tablename__ = 'groups'
#     id = Column(Integer, primary_key=True)
#     name = Column(VARCHAR(255))
#     description = Column(VARCHAR(255))
#
#
# class UserGroup(Base):
#     __tablename__ = 'user_groups'
#     user_id = Column(Integer, ForeignKey('users.id'))
#     group_id = Column(Integer, ForeignKey('groups.id'))
